<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />  
        <title>Railway Official Website</title>
        <link rel="stylesheet" href="css/foundation.css"/>
        <link rel="stylesheet" href="css/normalize.css"/>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <script src="js/vendor/jquery.js"></script>
        <script src="js/ui/jquery-ui.js"></script>
        <script src="js/vendor/custom.modernizr.js"></script>
        <script src="js/ticketing.js"></script>
        <?php
        session_start();
        ?>
    </head>
    <body>
        <div id="myModal" class="reveal-modal medium" style="height: 500px;">
            <form class="custom" id="seatform">
                <input type="hidden" id="ticketnumber"/>
                <input type="hidden" name="action" value="getCoachmap"/>
                <div class="row">
                    <div class="row">
                        <div class="small-3 columns">
                            <label for="coach" class="inline">Select Coach </label>
                        </div>
                        <div class="small-4 left columns">
                            <select id="coach" name="coach" onchange="getCoachmap();">
                                <option value="0">Select Coach</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div id="coachmap" class="row" style="height: 415px; overflow: auto;">

                        </div>
                    </div>
                </div>
            </form>
            <a class="close-reveal-modal">&#215;</a>
        </div>
        <div id='overlay' style="display:none; opacity: 0.4;position: fixed;top: 0;left: 0;background-color: black;width: 100%;z-index: 5000;">
            <img src="img/loader.gif" style="opacity:1; position: absolute; top: 50%;left: 50%;margin-left:-16px;
                 margin-top:-16px';"><span>Please wait...</span></img>
        </div>
        <div>
            <nav class="top-bar">
                <ul class="title-area">
                    <li class="name" onClick="void(0);">
                        <h1><a href="#">Railway Official Website</a></h1>
                    </li>
                    <li class="divider"></li>
                    <li class="toggle-topbar menu-icon">
                        <a href="#"><span>menu</span></a>
                    </li>
                </ul>
                <section class="top-bar-section">
                    <ul class="right">
                        <li class="divider"></li>
                        <li><a href="index.php">Home</a></li>
                        <li class="divider"></li>
                        <li><a href="index.php">Forum</a></li>
                        <li class="divider"></li>
                        <?php
                        if (isset($_SESSION['username'])) {
                            echo '<li><a href="profile.php?mode=21">My profile</a></li>';
                            echo '<li class="divider"></li>';
                            echo '<li><a href="logout.php">Logout</a></li>';
                            echo '<li class="divider"></li>';
                        }
                        else
                            echo '<li><a href="loginPage.php">Login</a></li>';
                        echo '<li class="divider"></li>';
                        ?>
                    </ul>
                </section>
            </nav>
        </div>
        <div class="row">
            <?php
            if (isset($_SESSION['username']) && isset($_SESSION['ticketdetails'])) {
                $data = unserialize($_SESSION['ticketdetails']);
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <input type="hidden" id="fare" value="<?php echo $data['fare']; ?>"/>
                                <input type="hidden" id="value" value="0"/>
                                <div class="small-11 large-offset-1 show-for-small columns">
                                    <table>
                                        <tr>
                                            <td style="width: 150px">Date</td><td style="width: 20px">:</td><td style="width: 150px"><?php echo $data['date']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Route Name</td><td>:</td><td><?php echo $data['route']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Schedule Name</td><td>:</td><td><?php echo $data['schedule']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Origin</td><td>:</td><td><?php echo $data['origin']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Destination</td><td>:</td><td><?php echo $data['destin']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Departure</td><td>:</td><td><?php echo $data['departure']; ?></td>
                                        </tr>
                                        <tr>
                                            <td>Arrival</td><td>:</td><td><?php echo $data['arrival']; ?></td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="small-11 large-offset-1 hide-for-small columns">
                                    <table>
                                        <thead>
                                            <tr>
                                                <th>Date</th>
                                                <th>Route Name</th>
                                                <th>Schedule Name</th>
                                                <th>Origin</th>
                                                <th>Destination</th>
                                                <th>Departure</th>
                                                <th>Arrival</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td><?php echo $data['date']; ?></td>
                                                <td><?php echo $data['route']; ?></td>
                                                <td><?php echo $data['schedule']; ?></td>
                                                <td><?php echo $data['origin']; ?></td>
                                                <td><?php echo $data['destin']; ?></td>
                                                <td><?php echo $data['departure']; ?></td>
                                                <td><?php echo $data['arrival']; ?></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="row">
                                <div class="large-11 large-offset-1 columns">
                                    <div class="row">
                                        <form id="couponform" class="custom">
                                            <input type="hidden" name="action" value="checkCoupon"/>
                                            <div class="large-3 columns">
                                                <label for="check" class="inline">
                                                    <input type="checkbox" id="check" onchange="enableCoupon(this);"/>
                                                    <span class="custom checkbox"></span>
                                                    Have a coupon?
                                                </label>
                                            </div>
                                            <div class="large-7 columns">
                                                <input type="text" id="coupon" name="coupon" disabled/>
                                                <small id="couponErr" class="error" style="display: none"></small>
                                            </div>
                                            <div class="large-2 columns">
                                                <input type="button" id="submitcoupon"value="Submit" class="button small right" disabled onclick="checkCoupon();"/>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="row">
                                        <div id="couponresult" class="small-12 columns alert-box" data-alert style="display: none">

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="small-12 columns">
                                            <form id="ticketno">
                                                <input type="hidden" name="action" value="generateTicketTemplete"/>
                                                <input type="hidden" name="emptyseat" value="<?php echo $data['emptyseat']; ?>"/>
                                                <div class="row">
                                                    <div class="small-3 small-offset-1 columns">
                                                        <label for="number" class="inline">No. of ticket</label>
                                                    </div>
                                                    <div class="small-6 left columns">
                                                        <input type="text" id="number" name="number" onchange="checkNumeric(this);"/>
                                                        <small class="error" id="numberErr" style="display: none"></small>
                                                    </div>
                                                    <div class="small-2 columns">
                                                        <input type="button" value="Go" class="small button left" onclick="generateTemplete();"/>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="small-12 columns panel">
                                            <div id="ticketdiv" class="row">

                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="small-12 columns">
                                            <?php if (isset($_SERVER['HTTP_REFERER'])) { ?>
                                                <input type="button" class="small button" onclick="atomicCleanUp('<?php echo $_SERVER['HTTP_REFERER']; ?>');" value="Back"/>
                                                <?php
                                            }
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li id="22"><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li id="23"><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li id="24"><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li id="25"><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li id="26" class="active"><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } elseif (isset($_SESSION['username'])) {
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns panel">
                                    You have nothing to do here, please select your schedule at <a href="profile.php?mode=26">here</a> first.
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li id="22"><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li id="23"><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li id="24"><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li id="25"><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li id="26"><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } else {
                ?>
                <div class="row">
                    <div class="large-10 large-offset-1 columns panel">
                        You do not have the permission to access this page, please <a href="loginPage.php">login</a> first.
                        <?php
                        if (isset($_SERVER['HTTP_REFERER'])) {
                            echo '<br/>Click <a href="' . $_SERVER['HTTP_REFERER'] . '">here</a> to back to previous page.';
                        }
                        ?>
                    </div>
                </div>
                <?php
            }
            ?>

        </div>
        <footer class="row">
            <div class="large-12 columns">
                <hr />
                <div class="row">
                    <div class="large-4 columns">
                        <p>&copy; Copyright 2013.</p>
                    </div>
                    <div class="large-6 columns">
                        <ul class="inline-list right">
                            <li><a href="aboutus.php">About Us</a></li>
                            <li><a href="contactus.php">Contact Us</a></li>
                            <li><a href="terms.php">Terms and Condition</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </footer>
        <script src="js/foundation.min.js"></script>
        <script>
                                $(document).foundation();
        </script>
    </body>
</html>